var app = getApp();

Page(Object.assign({},{
    data:{
        inited : false,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;
        wx.setNavigationBarTitle({
          title: '核销卡券',
        });
        app.com.auth(function(user){
            if( options.scene ){
                self.setData({
                    cid : options.scene,
                    inited : true,
                },function(){
                    self.select();
                });
            }else{
                app.com.toast('请重新扫码');return false;
            }
        })
    },
    inputvalue(e){
        var self = this;
        self.setData({
            code : e.detail.value
        })
    },
    select(){
        var self = this;
        if( !self.data.cid ) {
            app.com.toast('请重新扫码');return false;
        }
        app.com.http('admin','POST',{op:'selecthexiaocard',cid:self.data.cid},0,false,'','',function(res){
            if (!res.data.errno && res.data ) {
                self.setData({
                    card : res.data.data.card,
                    params : res.data.data.params,
                })
            }else{
                app.com.toast( res.data.message );
                self.setData({
                    order : null,
                    good : null,
                })
                if( res.data.errno == 2 ){
                    wx.navigateTo({
                        url : '/zofui_sales/pages/admin/login'
                    });
                }
            }
        });
    },
    hexiao(){
        var self = this;
        if( !self.data.cid ) {
            app.com.toast('请重新扫码');return false;
        }

        app.com.http('admin','POST',{op:'hexiaocard',cid:self.data.cid},0,true,'','',function(res){
            if (!res.data.errno) {
                app.com.toast(res.data.message,'success',function(){
                    self.setData({
                        ishexiao : 1 ,
                        'card.takedstatus' : 1 ,
                        'card.lasttimes' : (self.data.card.lasttimes-1) ,
                    })
                })
            }else{
                app.com.toast( res.data.message );
                if( res.data.errno == 2 ){
                    wx.navigateTo({
                        url : '/zofui_sales/pages/admin/login'
                    });
                }
            }
        });
    },
    onPullDownRefresh: function () {
        wx.stopPullDownRefresh();
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    scan(e){
        wx.scanCode({
            success : function(res){
                if( res.path ){
                    var path =  res.path.indexOf("/") == 0 ? res.path : '/'+res.path;
                    wx.navigateTo({
                      url: path,
                    });
                }
            }
        });
    }
}))